<?php

defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';

if($_RQ['op']=='list'){
	$y1 = mktime(0,0,0,1,1,date('Y'));
	$y2 = mktime(0,0,0,2,1,date('Y'));
	$y3 = mktime(0,0,0,3,1,date('Y'));
	$y4 = mktime(0,0,0,4,1,date('Y'));
	$y5 = mktime(0,0,0,5,1,date('Y'));
	$y6 = mktime(0,0,0,6,1,date('Y'));
	$y7 = mktime(0,0,0,7,1,date('Y'));
	$y8 = mktime(0,0,0,8,1,date('Y'));
	$y9 = mktime(0,0,0,9,1,date('Y'));
	$y10 = mktime(0,0,0,10,1,date('Y'));
	$y11 = mktime(0,0,0,11,1,date('Y'));
	$y12 = mktime(0,0,0,12,1,date('Y'));
	$p1=pdo_fetch('select SUM(price) from '. tablename('jy_weishop_order').' where uniacid = '.$_SESSION['uniacid'].' and ispay=1 and finishtime between '.$y1.' and '.$y2);
	$p1=$p1['SUM(price)'];
	$p2=pdo_fetch('select SUM(price) from '. tablename('jy_weishop_order').' where uniacid = '.$_SESSION['uniacid'].' and ispay=1 and finishtime between '.$y2.' and '.$y3);
	$p2=$p2['SUM(price)'];
	$p3=pdo_fetch('select SUM(price) from '. tablename('jy_weishop_order').' where uniacid = '.$_SESSION['uniacid'].' and ispay=1 and finishtime between '.$y3.' and '.$y4);
	$p3=$p3['SUM(price)'];
	$p4=pdo_fetch('select SUM(price) from '. tablename('jy_weishop_order').' where uniacid = '.$_SESSION['uniacid'].' and ispay=1 and finishtime between '.$y4.' and '.$y5);
	$p4=$p4['SUM(price)'];
	$p5=pdo_fetch('select SUM(price) from '. tablename('jy_weishop_order').' where uniacid = '.$_SESSION['uniacid'].' and ispay=1 and finishtime between '.$y5.' and '.$y6);
	$p5=$p5['SUM(price)'];
	$p6=pdo_fetch('select SUM(price) from '. tablename('jy_weishop_order').' where uniacid = '.$_SESSION['uniacid'].' and ispay=1 and finishtime between '.$y6.' and '.$y7);
	$p6=$p6['SUM(price)'];
	$p7=pdo_fetch('select SUM(price) from '. tablename('jy_weishop_order').' where uniacid = '.$_SESSION['uniacid'].' and ispay=1 and finishtime between '.$y7.' and '.$y8);
	$p7=$p7['SUM(price)'];
	$p8=pdo_fetch('select SUM(price) from '. tablename('jy_weishop_order').' where uniacid = '.$_SESSION['uniacid'].' and ispay=1 and finishtime between '.$y8.' and '.$y9);
	$p8=$p8['SUM(price)'];
	$p9=pdo_fetch('select SUM(price) from '. tablename('jy_weishop_order').' where uniacid = '.$_SESSION['uniacid'].' and ispay=1 and finishtime between '.$y9.' and '.$y10);
	$p9=$p9['SUM(price)'];
	$p10=pdo_fetch('select SUM(price) from '. tablename('jy_weishop_order').' where uniacid = '.$_SESSION['uniacid'].' and ispay=1 and finishtime between '.$y10.' and '.$y11);
	$p10=$p10['SUM(price)'];
	$p11=pdo_fetch('select SUM(price) from '. tablename('jy_weishop_order').' where uniacid = '.$_SESSION['uniacid'].' and ispay=1 and finishtime between '.$y11.' and '.$y12);
	$p11=$p11['SUM(price)'];
	$p12=pdo_fetch('select SUM(price) from '. tablename('jy_weishop_order').' where uniacid = '.$_SESSION['uniacid'].' and ispay=1 and finishtime > '.$y12);
	$p12=$p12['SUM(price)'];
	/*$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>3,'finishtime >'=>$y1);
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','price','finishtime');
	$list=pdo_getslice('jy_weishop_order',$params,array($pindex,$psize),$total,$fields,'','id desc');
	
	if($list){
		foreach($list as &$v){
			$time=$v['finishtime'];
			if($y2 > $time && $time >= $y1){
				$p1 +=$v['price'];
			}elseif($y3 > $time && $time >= $y2){
				$p2 +=$v['price'];
			}
			elseif($y4 > $time && $time >= $y3){
				$p3 +=$v['price'];
			}
			elseif($y5 > $time && $time >= $y4){
				$p4 +=$v['price'];
			}
			elseif($y6 > $time && $time >= $y5){
				$p5 +=$v['price'];
			}
			elseif($y7 > $time && $time >= $y6){
				$p6 +=$v['price'];
			}
			elseif($y8 > $time && $time >= $y7){
				$p7 +=$v['price'];
			}
			elseif($y9 > $time && $time >= $y8){
				$p8 +=$v['price'];
			}
			elseif($y10 > $time && $time >= $y9){
				$p9 +=$v['price'];
			}
			elseif($y11 > $time && $time >= $y10){
				$p10 +=$v['price'];
			}
			elseif($y12 > $time && $time >= $y11){
				$p11 +=$v['price'];
			}else{
				$p12 +=$v['price'];
			}
		}
	}*/
	$total=$p1+$p2+$p3+$p4+$p5+$p6+$p7+$p8+$p9+$p10+$p11+$p12;
	$return['list']=array('0'=>array('m'=>'1月','t'=>$p1),'1'=>array('m'=>'2月','t'=>$p2),'2'=>array('m'=>'3月','t'=>$p3),'3'=>array('m'=>'4月','t'=>$p4),'4'=>array('m'=>'5月','t'=>$p6),'5'=>array('m'=>'6月','t'=>$p6),'6'=>array('m'=>'7月','t'=>$p7),'7'=>array('m'=>'8月','t'=>$p8),'8'=>array('m'=>'9月','t'=>$p9),'9'=>array('m'=>'10月','t'=>$p10),'10'=>array('m'=>'11月','t'=>$p11),'11'=>array('m'=>'12月','t'=>$p12));	
	if($total){
		foreach($return['list'] as &$v){
			$v['r']=$v['t']/$total*100;
		}
	}
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		
		'list'=>array('data'=>'list','delall'=>false,'del_one'=>false,'edit'=>false,'list'=>array(
			array('name'=>'m','title'=>'月份','type'=>'string'),
			array('name'=>'t','title'=>'销售额(元)(已支付)','type'=>'string'),
			array('name'=>'r','title'=>'占比(%)','type'=>'string'),
		)),
	);
	$return['htmls']=$htmls;
	
	exi($return);
}
